package com.gzwh.weblib.basic;


import com.gzwh.weblib.bean.Result;
import com.gzwh.weblib.utils.RxExceptionUtil;


import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public abstract class BaseObserver<T> implements Observer<Result<T>> {

    private static final String TAG = "BaseObserver";


    @Override
    public void onNext(Result<T> response) {
        System.out.println("请求成功：" + response.toString());
        //在这边对 基础数据 进行统一处理  举个例子：
        if (response.isSuccess()) {
            onSuccess(response);
        } else {
            onFailure(null, response.getMessage());
        }
    }

    @Override
    public void onError(Throwable e) {//服务器错误信息处理
        onFailure(e, RxExceptionUtil.exceptionHandler(e));
        e.printStackTrace();
    }

    @Override
    public void onComplete() {

    }

    @Override
    public void onSubscribe(Disposable d) {
    }

    public abstract void onSuccess(Result<T> result);

    public abstract void onFailure(Throwable e, String errorMsg);


}
